package com.yao.smy.controller;

import com.yao.smy.domain.Visitor;
import com.yao.smy.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/visitors")
public class VisitorController {

    @Autowired
    private VisitorService visitorService;

    // 新增或更新游客
    @PostMapping
    public void saveVisitor(@RequestBody Visitor visitor) {
         visitorService.addVisitor(visitor);
    }

    // 根据身份证删除游客
    @DeleteMapping("/{idCard}")
    public void deleteVisitor(@PathVariable String idCard) {
        visitorService.deleteVisitor(idCard);
    }

    // 根据身份证查询游客
    @GetMapping("/{idCard}")
    public Visitor getVisitorByIdCard(@PathVariable String idCard) {
        return visitorService.getVisitor(idCard);
    }

    // 查询所有游客
    @GetMapping
    public List<Visitor> getAllVisitors() {
        return visitorService.getAllVisitors();
    }
}
